package com.atguigu.gmall.all.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.order.client.OrderFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author atguigu-mqx
 */
@Controller
public class OrderController {

    @Autowired
    private OrderFeignClient orderFeignClient;
    //  http://order.gmall.com/trade.html
    @GetMapping("trade.html")
    public String tradeIndex(HttpServletRequest request, Model model){
        //  userAddressList  detailArrayList totalNum totalAmount
        //  第一种存储方式！
        //        request.setAttribute("userAddressList","");
        //        request.setAttribute("detailArrayList","");
        //        request.setAttribute("totalNum","");
        //        request.setAttribute("totalAmount","");
        //        request.setAttribute("tradeNo",orderFeignClient.getTradeNo());
        //  第二种存储方式： 将上述四个key 统一在service-order中存储！
        Result<Map> result =  orderFeignClient.trade();
        model.addAllAttributes(result.getData());
        //  返回页面视图
        return "order/trade";
    }

    //  http://order.gmall.com/myOrder.html
    @GetMapping("myOrder.html")
    public String myOrder(){
        //  返回订单页面名称
        return "order/myOrder";
    }

}
